
with Ada.Text_IO; use Ada.Text_IO; 

procedure leet74_search2dmatrix is
    type vector is array (positive range<>) of integer;
    type matrix is array (positive range <>, positive range <>) of integer;

    function search2d(m: in matrix; t: in Integer) return Boolean is 
        rows : Integer := m'length(1);
        cols : Integer := m'length(2);
        found: Boolean := False;
    begin
        for i in m'range(1) loop
            --put(m(i,4)'image);
            if t > m(i,1) and t < m(i,cols) then
                for j in m'range(2) loop
                    if t = m(i,j) then
                        found := True;
                    end if;
                end loop;
            end if;
        end loop;
        return  found;
    end search2d;

    procedure main is
        m : matrix := ((1,3,5,7),
                        (10,11,16,20),
                        (23,30,34,60));
        t1 : Integer := 3;
        t2 : Integer := 13;
    begin
        if search2d(m,t1) then
            put_line(t1'image & " is there.");
        end if;
        if search2d(m,t2) then
            put_line(t2'image & " is there.");
        end if;
    end main;
begin
    put_line("This is leetcode challenge 74 Search 2D Matrix.");
    put_line("https://leetcode.com/problems/search-a-2d-matrix/");
    main;
end leet74_search2dmatrix;

